#ifndef SSP_COLLEGE_H
#define SSP_COLLEGE_H

#include <list>
#include <string>
#include <functional>
#include <any>
#include <imf/net/loop.h>
#include <imf/net/threadloop.h>
#include <imf/ssp/sspclient.h>
#include "httplib.h"

class SSPCollege
{
  public:
    //第一个是相机IP，第二个是自定义数据
    SSPCollege(
      const std::vector<std::pair<std::string,std::any>> & ipList,
      std::function<void(const char*,std::size_t size,unsigned long frameID,std::any & userData)> funcHandle);
    virtual ~SSPCollege();
    void StartShot();
    void StopShot();
  private:
    class CameraObject
    {
      public:
        CameraObject(std::string ip,std::any userData,imf::Loop* loop,std::function<void(const char*,std::size_t size,unsigned long frameID,std::any & userData)> func);
        virtual ~CameraObject();
        bool GetTestStatus();
        void StartShot(); //在开始拍摄前会自动执行测试，然后需要手动暂停测试
        void StopShot();
      private:
        httplib::Client client;
        imf::SspClient* ssp_client;
        std::any userData;
        std::string ip;
        bool TestStatus=false;
        bool RunTest=true;
        void on_264_callback(struct imf::SspH264Data * h264);
        void on_audio_callback(struct imf::SspAudioData * audio);
        void on_meta_callback(struct imf::SspVideoMeta * v,struct imf::SspAudioMeta* a,struct imf::SspMeta * m);
        void on_disconnect_callback();
        std::function<void(const char*,std::size_t size,unsigned long frameID,std::any & userData)> funcHandle;
    };
    std::list<CameraObject> cameraObjectList;
    std::unique_ptr<imf::ThreadLoop> threadLooper;
};

#endif
